home *** CD-ROM | disk | FTP | other *** search
Wrap
const WL_Wiktionary_section_names = [ "Abbreviation", "Acronym", "Adjective", "Adverb", "Anagrams", "Article", "Cardinal number", "Cardinal numeral", "Compounds", "Conjugation", "Conjunction", "Contraction", "Counter", "Declension", "Descendants", "Determiner", "Idiom", "Infix", "Inflection", "Initialism", "Interjection", "Noun", "Number", "Numeral", "Ordinal number", "Ordinal numeral", "Participle", "Particle", "Phrase", "Pinyin syllable", "Prefix", "Preposition", "Pronoun", "Proper noun", "Proverb", "Quotations", "Romaji", "Trivia", "Verb", "Verb form", "Han character", "Hiragana character", "Katakana character", ]; /** * Create a new English Wiktionary handler and tie it to the WikiLook interface **/ function WikiLook_en (WikiLook) { this.WL = WikiLook } WikiLook_en.prototype.responseFetchReal = function (response) { /*if (response.indexOf("Wiktionary does not yet have an entry for") == -1) { // See comments at the end of the function*/ this.WL._mainLanguage=WikiLookdb_pref.getCharPref("WikiLookMainLanguage"); var pattern=' href="/w/index.php?title='; var titleStarts=response.indexOf(pattern) var TitleName=response.substring(titleStarts+pattern.length, response.indexOf("&action=",titleStarts+pattern.length)); //TitleName=unescape(TitleName); var lngName=""; var lngStarts='<span class="mw-headline" id="'; var mlngstrStarts=lngStarts+this.WL._mainLanguage+'">'; var mlngstrStops='<h2><span class="editsection">[<a '; var mlngStart=response.indexOf(mlngstrStarts)+mlngstrStarts.length+1; if (mlngStart-mlngstrStarts.length-1==-1) { mlngStart=response.indexOf(mlngstrStops); } else {this.WL._mainLngFound=true;} /* if (this.WL._goForIt==true&&this.WL._defFound==true) { this.formOf(); return true; }*/ var mlngStops=response.indexOf(mlngstrStops, mlngStart+1); if (this.WL._mainLngFound){ if (mlngStops!=-1) { //if main language starts and stops, grab the section response=response.substring(mlngStart-1,mlngStops); } else { //if it only starts, grab HTML from start to end of page response=response.substring(mlngStart-1,response.length); } lngName=response.substring(0,response.indexOf('<')); } else { //If no main language detected, grab first languadge on the page if (response.indexOf(mlngstrStops,response.indexOf(lngStarts))!=-1) { response=response.substring(response.indexOf(lngStarts)+lngStarts.length , response.indexOf(mlngstrStops,response.indexOf(lngStarts))); } else { response=response.substring(response.indexOf(lngStarts)+lngStarts.length , response.length); } lngName=response.substring(0,response.indexOf('">')); } //////////////////////// this.WL._outText = ""; var sectionName = ""; var defFoundNow = false; var secIdx=0; for(secIdx=0; secIdx < WL_Wiktionary_section_names.length; secIdx++) { sectionName = WL_Wiktionary_section_names[secIdx]; r = false; r = this.wiktionaryGetSection(response,sectionName); if (r != false) { this.WL._outText += "<b>"+sectionName+"</b>"+r; defFoundNow = true; } } if (this.WL._defFound) { this.WL._outText = this.WL.wiktionarySetStyle(this.WL._outText); if (this.WL._outText!="") {this.WL._outTextForFormOf=this.WL._outText} //if(!this.WL.attachDiv()) return; tStem = ""; var tStem2=""; var audioStarts='<span class="unicode audiolink"> <a href="'; if (WikiLookdb_pref.getBoolPref("WikiLookAutoAudio") == true) { // if (response.indexOf(audioStarts)!=-1) { tStem = response.substring(response.indexOf(audioStarts)+audioStarts.length, response.indexOf('" class="internal"', response.indexOf(audioStarts)+audioStarts.length)); if (!this.WL._audioLinkShown) { tStem2= '<audio src="' + tStem + '" autoplay></audio>' + ''; } } } if ((window.navigator.userAgent.indexOf("Firefox/3.0")==-1)&&(window.navigator.userAgent.indexOf("Firefox/2.0")==-1)){ if (response.indexOf(audioStarts)!=-1) { tStem = response.substring(response.indexOf(audioStarts)+audioStarts.length, response.indexOf('" class="internal"', response.indexOf(audioStarts)+audioStarts.length)); if (!this.WL._audioLinkShown) { tStem2 = tStem2 + '<audio id="OGG" src="' + tStem + '" ></audio>' + '<a class="WikiLookTitle" href="javascript:void(0);"><img id="audioPlayback" style="border-style: none" title="Click here to hear how the word is pronounced." src="chrome://wikilook/skin/audio.png" onclick="document.getElementById(\'OGG\').play()"></a>'; this.WL._audioLinkShown=true; } } } var pronunciation = ""; var pronStarts='<span class="IPA">/'; if (response.indexOf(pronStarts)!=-1) { pronunciation = 'IPA:<b><i> /' + response.substring(response.indexOf(pronStarts)+pronStarts.length, response.indexOf('/</span>', response.indexOf(pronStarts)+pronStarts.length)) + '/</b></i>'; } /*pronStarts='<tt class="SAMPA">/'; //should we include SAMPA? Not sure. If yes, please uncomment. if (response.indexOf(pronStarts)!=-1) { pronunciation = pronunciation +'SAMPA:<b><i> ' + response.substring(response.indexOf(pronStarts)+pronStarts.length, response.indexOf('/</tt>', response.indexOf(pronStarts)+pronStarts.length)) + '</b></i>, '; }*/ pronStarts='<span class="AHD enPR">'; if (response.indexOf(pronStarts)!=-1) { pronunciation = pronunciation + ', enPR:<b><i> ' + response.substring(response.indexOf(pronStarts)+pronStarts.length, response.indexOf('</span>', response.indexOf(pronStarts)+pronStarts.length)) + '</b></i>'; } if (pronunciation.length>2) {pronunciation = '( ' + pronunciation + ' )'} /*if (this.WL._thisIsAFormOf==false) { this.WL._div.style.left = this.WL.getNewWindowX() + "px"; this.WL._div.style.top =this.WL.getNewWindowY() + "px"; }*/ // Next line is needed so redirects from proper noun that starts with lower case are shown correctly, while not touching the way words in weird alphabets are shown, like ones in Amharic. //if (this.WL._currentWord.length==TitleName.length) {this.WL._currentWord=TitleName} if ((defFoundNow==true&&lngName=="English"&&this.WL._engDefFound==false&&this.WL._mainLngFound==false)||(defFoundNow==true&&this.WL._mainLngFound==true)||(defFoundNow==true&&this.WL._divIsDisplayed==false)||(defFoundNow==true&&this.WL._thisIsAFormOf==true)){ var copyOfCurrentWord=""; if (this.WL._currentWord==null) {copyOfCurrentWord=TitleName;} else {copyOfCurrentWord=this.WL._currentWord} this.WL._divIsDisplayed = true; if (this.WL._thisIsAFormOf==false) { this.WL._div.innerHTML = this.WL._CSS+"<a class='WikiLookTitle' href='javascript:void(0);'><img id='confDialog' style='border-style: none' title='Click here for configuration dialog.' src='chrome://wikilook/skin/config.png'></a> "; } else { this.WL._div.innerHTML =this.WL._div.innerHTML.replace(" autoplay", " ") +'<center><hr width="80%" align="center" border="2" noshade color="#F5F5F5"><\center><\hr><br>'; } this.WL._div.innerHTML =this.WL._div.innerHTML + "<a class='WikiLookTitle' style=\"color:"+this.WL._linkColor+";\" href='http://en.wiktionary.org/wiki/"+copyOfCurrentWord+"' style='font-size:12px;'><span class='popup_mainlink'>"+decodeURI(copyOfCurrentWord)/*.replace("%27","\'")*/.replace(/_/g," ")+"</span></a> " + " " + tStem2 + " " +'<b><i><font size=-5 color=#660033>'+lngName.replace(/_/g," ")+' </font></b></i> ' + pronunciation +"" +" <br/><br/>" +"<span style=\"display:block;font-family:arial;\">" +this.WL._outText +"</span>"; +"(retrieved from <a style=\"color:"+this.WL._linkColor+";\" href=http://www.wiktionary.org>wiktionary.org</a>)"; } if(this.WL._defFound==true&&lngName=="English"&&this.WL._engDefFound==false) {this.WL._engDefFound=true;} if((this.WL._goForIt==true&&this.WL._defFound==true)||(this.WL._mainLngFound==true&&this.WL._defFound==true)){ //this.WL.showDiv(); this.formOf(); return true; } } return false; /* FIXME This logic should use internal search suggestions of Wiktionary. CAREFUL! It could lead to empty articles! } else { if (response.indexOf('<li><big>Did you mean <b><span id="did-you-mean"><a href="/wiki/')!=-1) { var a=response.indexOf('<li><big>Did you mean <b><span id="did-you-mean"><a href="/wiki/'); var pattern='><em>'; var titleStarts=response.indexOf(pattern,a) var TitleName=response.substring(a, response.indexOf(pattern,a+a.length)); this.WL._isRequestFetching = true; this.WL._currentWord=TitleName; this.WL.requestFetchWord2(TitleName); return true; } return false; }*/ return false; } WikiLook_en.prototype.wiktionaryGetSection = function (sourceText,sectionName) { // Convert to lowercase to find pattern position. // Discard lowercase needle and hay later. var sNameLower = sectionName.replace(" ","_","ig"); //.toLowerCase(); var patternLower = 'class="mw-headline" id="' + sNameLower; //+ '">' + sectionName + '</span></h'; var sourceLower = sourceText;//.toLowerCase(); var headPos = sourceLower.indexOf(patternLower); if ( headPos != -1 ) { this.WL._defFound = true; var u = sourceText.substring(headPos+patternLower.length); u = this.WL.cutHead_preserve("<ol>", u); if (u==null) {return false;} u = this.WL.cutTail_preserve("</ol>", u); //u = u.replace(" href=\""," href=\"http://en.wiktionary.org", "gi"); return u; } return false; } /** * This checks the current entry to see if it is a "form of" another word. * If it is then we download the word of which it is a form and append that * to the display. **/ WikiLook_en.prototype.formOf = function () { //alert(this.WL._outTextForFormOf); //if (this.WL._outTextForFormOf.indexOf("spelling of")!=-1) {alert(this.WL._outTextForFormOf.substring(this.WL._outTextForFormOf.indexOf("spelling of"),this.WL._outTextForFormOf.indexOf("spelling of")+350));} //Only allow an extra two formOf's to be added if (this.WL._thisIsAFormOfFormOf == true) return; if (this.WL._thisIsAFormOf == true) this.WL._thisIsAFormOfFormOf = true; var wordtemp=""; var word=""; //This is the current contents of the form of templates, lets hope they don't change var pattern = 'of <span class="mention"><a class="WikiLook" href="http://en.wiktionary.org/wiki/'; //Extract the word of which we are a form var a = this.WL._outTextForFormOf.indexOf(pattern); if (a!=-1) { word=this.WL._outTextForFormOf.substring(a+pattern.length, this.WL._outTextForFormOf.indexOf('" title="',a)); wordtemp=word.substring(0,word.indexOf("#")); } if (word!="") { if (word.length>wordtemp.length&&wordtemp.length>0){word=wordtemp;} this.WL._thisIsAFormOf=true; this.WL._currentWord=word; this.WL.requestFetchWord2(word); return; } //Repeat for other forms of word that we've found word=""; wordtemp=""; pattern = 'state of being <a class="WikiLook" href="http://en.wiktionary.org/wiki/'; var a = this.WL._outTextForFormOf.indexOf(pattern); if (a!=-1) { word=this.WL._outTextForFormOf.substring(a+pattern.length, this.WL._outTextForFormOf.indexOf('" title="',a)); wordtemp=word.substring(0,word.indexOf("#")); } if (word!="") { if (word.length>wordtemp.length&&wordtemp.length>0){word=wordtemp;} this.WL._thisIsAFormOf=true; this.WL._currentWord=word; this.WL.requestFetchWord2(word); return; } word=""; wordtemp=""; pattern = 'form of <a class="WikiLook" href="http://en.wiktionary.org/wiki/'; var a = this.WL._outTextForFormOf.indexOf(pattern); if (a!=-1) { word=this.WL._outTextForFormOf.substring(a+pattern.length, this.WL._outTextForFormOf.indexOf('" title="',a)); wordtemp=word.substring(0,word.indexOf("#")); } if (word!="") { if (word.length>wordtemp.length&&wordtemp.length>0){word=wordtemp;} this.WL._thisIsAFormOf=true; this.WL._currentWord=word; this.WL.requestFetchWord2(word); return; } word=""; wordtemp=""; pattern = 'form of <b class="WikiLook"><a class="WikiLook" href="http://en.wiktionary.org/wiki/'; var a = this.WL._outTextForFormOf.indexOf(pattern); if (a!=-1) { word=this.WL._outTextForFormOf.substring(a+pattern.length, this.WL._outTextForFormOf.indexOf('" title="',a)); wordtemp=word.substring(0,word.indexOf("#")); } if (word!="") { if (word.length>wordtemp.length&&wordtemp.length>0){word=wordtemp;} this.WL._thisIsAFormOf=true; this.WL._currentWord=word; this.WL.requestFetchWord2(word); return; } }